package com.smzd.ccms.business;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smzd.ccms.dao.AttachmentDao;
import com.smzd.ccms.domain.Attachment;
import com.smzd.core.dao.IDao;
import com.smzd.framework.core.business.AbstractFGService;
import com.smzd.framework.utils.db.FGRowConverter;

@Service
public class AttachmentService extends AbstractFGService<Attachment> {
	private static AttachmentService instance;

	public static AttachmentService getInstance() {
		return instance;
	}
	@PostConstruct
	protected void initSekeleton() {
		instance = this;
	}
    @Autowired
    private AttachmentDao dao;
    
    @Override
    protected IDao<Attachment> getDao() {
        return dao;
    }
    
    @Override
    public FGRowConverter<Attachment> getConverter() {
        return converter;
    }

    private static FGRowConverter<Attachment> converter = new FGRowConverter<Attachment>() {
        @Override
        public Object[] convert(Attachment elem) {
            Object[] fs = new Object[]{
                    elem.getId(),
                    elem.getName(),
                    elem.getDescription(),
                    elem.getPath(),
                    elem.getType()
                };
                return fs;
        }
    };

	public List<Attachment> getAllAttachments(int scopeId) {
	    return dao.getAllAttachments(scopeId);
    }

	public List<Attachment> getAllAttachmentsForFirstArticle(int chId) {
	    return dao.getAllAttachmentsForFirstArticle(chId);
    }
}